{%TEMPLATE->struct/head%}
{%TEMPLATE->struct/menu%}
<h2>Access Group '[[htmlentities([[group.getGroupName()]], ENT_QUOTES, "UTF-8")]]'</h2>
{%TEMPLATE->struct/messages%}
<h3>User Members</h3>
<div class="card">
  <div class="table-responsive">
    <table class="table table-bordered">
		  <tr>
			  <th>User ID</th>
			  <th>Username</th>
			  <th>Action</th>
		  </tr>
		  {{FOREACH user;[[users]]}}
			  <tr>
				  <td>[[user.getId()]]</td>
				  <td><a href="users.php?id=[[user.getId()]]">[[htmlentities([[user.getUsername()]], ENT_QUOTES, 'UTF-8')]]</a></td>
				  <td>
					  <form class="float-right" action="groups.php?id=[[group.getId()]]" method="POST" onSubmit="if (!confirm('Really remove user [[htmlentities([[user.getUsername()]], ENT_QUOTES, 'UTF-8')]] from this group?')) return false;">
						  <input type="hidden" name="action" value="[[$DAccessGroupAction::REMOVE_USER]]">
						  <input type="hidden" name="csrf" value="[[csrf]]">
						  <input type="hidden" name="userId" value="[[user.getId()]]">
						  <input type="hidden" name="groupId" value="[[group.getId()]]">
						  <button type="submit" class='btn btn-danger' data-toggle="tooltip" data-placement="top" title="Remove"><i class="fas fa-ban" aria-hidden="true"></i></button>
					  </form>
				  </td>
			  </tr>
		  {{ENDFOREACH}}
		  {{IF [[sizeof([[users]])]] == 0}}
			  <tr><td>---</td><td>---</td><td>---</td></tr>
		  {{ENDIF}}
		  <tr>
			  <td colspan="3">
				  <form class="form-inline" action="groups.php?id=[[group.getId()]]" method="POST">
					  <input type="hidden" name="csrf" value="[[csrf]]">
					  <input type="hidden" name="groupId" value="[[group.getId()]]">
					  <input type="hidden" name="action" value="[[$DAccessGroupAction::ADD_USER]]">
					  <select class="form-control" name="userId" title="User">
						  {{FOREACH user;[[allUsers]]}}
							  <option value="[[user.getId()]]">[[htmlentities([[user.getUsername()]], ENT_QUOTES, 'UTF-8')]]</option>
						  {{ENDFOREACH}}
					  </select>&nbsp;&nbsp;
					  <button type="submit" class="btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}">Add User</button>
				  </form>
			  </td>
		  </tr>
	  </table>
  </div>
</div>
<h3>Agent Members</h3>
<div class="card">
  <div class="table-responsive">
    <table class="table table-bordered">
		  <tr>
			  <th>Agent ID</th>
			  <th>Agent Name</th>
			  <th>Agent Owner</th>
			  <th>Action</th>
		  </tr>
		  {{FOREACH agent;[[agents]]}}
			  <tr>
				  <td>[[agent.getId()]]</td>
				  <td><a href="agents.php?id=[[agent.getId()]]">[[htmlentities([[agent.getAgentName()]], ENT_QUOTES, 'UTF-8')]]</a></td>
				  <td>
					  {{IF [[agent.getUserId()]] > 0}}
						  <a href="users.php?id=[[agent.getUserId()]]">[[htmlentities([[Util::getUsernameById([[agent.getUserId()]])]], ENT_QUOTES, 'UTF-8')]]</a>
					  {{ELSE}}
						  ---
					  {{ENDIF}}
				  </td>
				  <td>
					  <form class="float-right" action="groups.php?id=[[group.getId()]]" method="POST" onSubmit="if (!confirm('Really remove agent [[htmlentities([[agent.getAgentName()]], ENT_QUOTES, 'UTF-8')]] from this group?')) return false;">
						  <input type="hidden" name="action" value="[[$DAccessGroupAction::REMOVE_AGENT]]">
						  <input type="hidden" name="csrf" value="[[csrf]]">
						  <input type="hidden" name="agentId" value="[[agent.getId()]]">
						  <input type="hidden" name="groupId" value="[[group.getId()]]">
						  <button type="submit" class='btn btn-danger' data-toggle="tooltip" data-placement="top" title="Remove"><i class="fas fa-ban" aria-hidden="true"></i></button>
					  </form>
				  </td>
			  </tr>
		  {{ENDFOREACH}}
		  {{IF [[sizeof([[agents]])]] == 0}}
			  <tr><td>---</td><td>---</td><td>---</td><td>---</td></tr>
		  {{ENDIF}}
		  <tr>
			  <td colspan="4">
				  <form class="form-inline" action="groups.php?id=[[group.getId()]]" method="POST">
					  <input type="hidden" name="csrf" value="[[csrf]]">
					  <input type="hidden" name="groupId" value="[[group.getId()]]">
					  <input type="hidden" name="action" value="[[$DAccessGroupAction::ADD_AGENT]]">
					  <select name="agentId" class="form-control" title="Agent">
						  {{FOREACH agent;[[allAgents]]}}
							  <option value="[[agent.getId()]]">[[htmlentities([[agent.getAgentName()]], ENT_QUOTES, 'UTF-8')]]</option>
						  {{ENDFOREACH}}
					  </select>&nbsp;&nbsp;
					  <button type="submit" class="btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}}">Add Agent</button>
				  </form>
			  </td>
		  </tr>
	  </table>
  </div>
</div>
{%TEMPLATE->struct/foot%}
